﻿(function($) {
	$(window).load(function() {
		
		find_message();
	})
})(jQuery);


function find_message(){
	var username = $.session.get("username");
	var secretkey = $.session.get("user_secretkey");
	$.ajax({
		url: "../../../../service",
		cache : false,
		data : {
			proc : "g_xmy.find_message",
			para : "['" + username + "','" + secretkey + "']"
		},
		dataType : "json",
		success : function(data) {
			if (data[0].TAG == "0") {
				window.location.href="./error.html";
			} else {
				document.getElementById("kanjia_result").value = data[0].RESULT_MSG;
				document.getElementById("kanjia_msg").value = data[0].CUTDOWN_MSG;
				$("input[name='r'][value='"+data[0].ISSHOW_RESULT+"']").attr("checked",true);
				$("input[name='sr'][value='"+data[0].ISSHOW_CUTDOWN+"']").attr("checked",true);
			}
		}
	});
}


function update_message(){
	var username = $.session.get("username");
	var secretkey = $.session.get("user_secretkey");
	var kanjia_result = document.getElementById("kanjia_result").value;
	if(kanjia_result==""){
		layer.alert("请填写砍价结果通知");
		return false;
	}
	var kanjia_msg = document.getElementById("kanjia_msg").value;
	if(kanjia_msg==""){
		layer.alert("请填写砍到底价通知");
		return false;
	}
	//是否开启砍价结果通知	
	if($("#kanjia_result_isnot").find("input")[0].checked==true){
		var kanjia_result_isnot = $("#kanjia_result_isnot").find("input")[0].value;
	}else{
		var kanjia_result_isnot = 0;
	}
	//是否开启砍到底价通知
	if($("#kanjia_msg_isnot").find("input")[0].checked==true){
		var kanjia_msg_isnot = $("#kanjia_msg_isnot").find("input")[0].value;
	}else{
		var kanjia_msg_isnot = 0;
	}
	
	$.ajax({
		url: "../../../../service",
		cache : false,
		data : {
			proc : "g_xmy.update_message",
			para : "['" + username + "','" + secretkey + "','" + kanjia_result + "','" + kanjia_msg + "','" 
						+ kanjia_result_isnot + "','" + kanjia_msg_isnot +"']"
		},
		dataType : "json",
		success : function(data) {
		//	console.log(JSON.stringify(data));
			if (data[0].TAG == "1") {
				layer.alert(data[0].MSG,function(index){
					 window.location.href="./message_set.html";
					 layer.close(index);
				}); 
			} else {
				layer.alert("保存失败");
			}
		}
	});
}


